package cashpointer.mobile.support;

import java.util.LinkedList;
import java.util.List;

import android.content.Context;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

@SuppressWarnings("unchecked")
public class ItemizedOverlayManager extends ItemizedOverlay {

	private List<OverlayItem> mOverlays = new LinkedList<OverlayItem>();
	private Context context;
	
	public ItemizedOverlayManager(Drawable defaultMarker) {
		super(boundCenterBottom(defaultMarker));
	}

	public void addOverlay(OverlayItem overlay) {
	    mOverlays.add(overlay);
	    populate();
	}
	
	@Override
	protected OverlayItem createItem(int i) {
		return mOverlays.get(i);
	}

	@Override
	public int size() {
		return mOverlays.size();
	}

	@Override
	protected boolean onTap(int i) {
		OverlayItem oi = mOverlays.get(i);
		if (oi != null) {
			StringBuffer sb = new StringBuffer();
			sb.append(oi.getTitle());
			sb.append("\n");
			sb.append(oi.getSnippet());
			NotificationSupportManager.showToastNotification(context, sb.toString());
		}
		return true;
	}

	public Context getContext() {
		return context;
	}

	public void setContext(Context context) {
		this.context = context;
	}	
}
